# -*- coding: utf-8 -*-
import os
import sys


liber_path = os.path.dirname(__file__)
liber_path = liber_path.replace("\\", "/")
if liber_path not in sys.path:
    sys.path.insert(0, liber_path)


from liberQt. splash import splash


@splash
def show_standalone():
    """
    show standalone
    :return:
    """
    from liberLibs import utils
    from liberScripts.widgets import liberwidget
    with utils.render_ui():
        sw = liberwidget.FramelessLiberWidget()
        sw.show()
        return sw


def show(frameless=True):
    """
    show in dcc softwares
    :param frameless:
    :return:
    """
    from liberLibs import utils, dcc
    from liberScripts.widgets import liberwidget
    with utils.render_ui():
        parent_win = dcc.get_parent_win()
        if frameless:
            sw = liberwidget.FramelessLiberWidget(parent_win)
        else:
            sw = liberwidget.LiberWidget(parent_win)
        sw.show()
        return sw


# ######################################################################################
# ##################################### show in maya ###################################
@splash
def show_in_maya_panel(*args):
    """
    show in maya panel
    :param args:
    :return:
    """
    from liberScripts.widgets.liberwidget import LiberWidget
    from liberLibs.dccLibs.Maya import show_as_panel
    show_as_panel(LiberWidget())


def show_slib_to_liber(*args):
    from liberScripts.widgets.slibtoliber import SlibToLiber
    from liberLibs import utils, dcc
    with utils.render_ui():
        parent_win = dcc.get_parent_win()
        stl = SlibToLiber(parent_win)
        stl.show()


def show_in_maya():
    """
    add menu in maya, and make the command connections
    :return:
    """
    import maya.cmds as mc
    import liber
    liber_menu = mc.menu('liber', label="Liber", tearOff=True, parent='MayaWindow')
    mc.menuItem(label="Show...", tearOff=True, parent=liber_menu, c=lambda *args: liber.show())
    mc.menuItem(label="show in panel...", tearOff=True, parent=liber_menu, c=liber.show_in_maya_panel)
    mc.menuItem(label="SLIB --> Liber", tearOff=True, parent=liber_menu, c=liber.show_slib_to_liber)


def maya_start_up():
    """
    when maya start up, execute.
    :return:
    """
    import maya.utils as mu
    mu.executeDeferred("import liber;reload(liber);liber.show_in_maya()")


# ######################################################################################
# ##################################### show in houdini ################################
# ######################################################################################
def show_in_houdini():
    show()


if __name__ == "__main__":
    show_standalone()
